package com.framework2.util;

import android.content.Context;

import com.asiainfo.iov.activity.BaseActivity;
import com.asiainfo.iov.activity.HomepageActivity;
import com.asiainfo.iov.configs.ConstantsME;
import com.framework.utils.PreferencesHelper;
import com.framework2.customviews.TitleView;
import com.framework2.popupwindow.GoHomepagePopupwindow;

/**
 * popupwindow工具--temp
 *
 * @author YobertJomi
 * className GohomePopupWindowUtil
 * created at  2017/3/17  13:01
 */
public class GohomePopupWindowUtil {
    private static volatile GohomePopupWindowUtil singleton;

    private GohomePopupWindowUtil() {
    }

    public static GohomePopupWindowUtil getInstance() {
        if (singleton == null) {
            synchronized (GohomePopupWindowUtil.class) {
                if (singleton == null) {
                    singleton = new GohomePopupWindowUtil();
                }
            }
        }
        return singleton;
    }

    public void showGohomePopupWindow(final Context context, final boolean showRightMarkIcon, TitleView titleView) {
        final GoHomepagePopupwindow pop = new GoHomepagePopupwindow(context);
        pop.showRightMarkIcon(showRightMarkIcon).setOnClickGobackHomeListener(new GoHomepagePopupwindow
                .OnClickGobackHomeListener() {
            @Override
            public void onClickGobackHome() {
                PreferencesHelper.getInstance().putInfo(ConstantsME.gotoHomepage, true);
                ((BaseActivity) (context)).startActivity(HomepageActivity.class);
                pop.dismiss();
            }
        }).setOnClickOpenMessageListener(new GoHomepagePopupwindow.OnClickOpenMessageListener() {
            @Override
            public void onClickOpenMessage() {
                pop.dismiss();
//                if (!ActivityTaskUtil.getInstance().isTopActivity(context, MessageCenterActivity.class.getName())) {
//                    ((BaseActivity) (context)).startActivity(MessageCenterActivity.class);
//                }
            }
        })
                .showAsDropDown(titleView.getRightLayout());
//        .showAtLocation(getWindow().getDecorView(),Gravity.CENTER, 0, 50);
    }
}
